package thread;

//  线程的等待    子线程等待主线程
public class demo11 {
    private static int sum = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();
        Thread t = new Thread(() -> {
            try {
                // t 线程等待 main 线程执行结束
                mainThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(sum);
            System.out.println("t 线程结束");
        });

        t.start();

        for (int i = 1; i <= 1000; i++) {
            sum += i;
        }
        System.out.println("主线程结束");

    }
}
